package leetcode.code1553;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

//超出内存限制
public class Solution implements IDebug {

	public int minDays(int n) {
		Integer[] dp = new Integer[n + 1];
		return this.f(n, dp);
	}

	private int f(int n, Integer[] dp) {
		if (n == 0) {
			return 0;
		}
		if (dp[n] != null) {
			return dp[n];
		}
		int ans1 = Integer.MAX_VALUE;
		if (n % 2 == 0) {
			ans1 = 1 + this.f(n / 2, dp);
		}
		int ans2 = Integer.MAX_VALUE;
		if (n % 3 == 0) {
			ans2 = 1 + this.f(n / 3, dp);
		}
		int ans3 = 1 + this.f(n - 1, dp);
		int ans = Math.min(ans1, Math.min(ans2, ans3));
		dp[n] = ans;
		return ans;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(4, this.minDays(10));

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
